import 'package:flutter/material.dart';
import 'package:kq_flutter_core_widget/utils/kq_screen_util.dart';
import 'package:kq_flutter_core_widget/utils/kq_multi_click_util.dart';
import 'package:kq_flutter_core_widget/widgets/button/kq_ink_well.dart';

import '../../resources/kq_theme_colors.dart';


/// 通用图标正方形按钮
///
/// @author 周卓
///
/// 基于系统的[IconButton]封装， 封装原因：直接用[IconButton]会占用不必要的很多空间
class KqIconButton extends StatelessWidget {
  /// 图标
  final Widget icon;

  /// 点击区域大小，默认40
  final double? size;

  /// 背景颜色，默认透明
  final Color? backgroundColor;

  /// 点击回调
  final VoidCallback? onPressed;

  const KqIconButton(
      {Key? key,
        required this.icon,
        this.size,
        this.backgroundColor,
        this.onPressed})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return UnconstrainedBox(
      child: SizedBox(
        width: size ?? 40.r,
        height: size ?? 40.r,
        child: KqInkWell(
          backgroundColor: backgroundColor ?? KqThemeColors.bgTransparent,
          borderWidth: 0,
          radius: (size ?? 40.r) / 2,
          onTap: () {
            if (KqMultiClickUtil.isMultiClick()) {
              return;
            }
            onPressed?.call();
          },
          child: icon,
        ),
      ),
    );
  }
}
